package com.sx.micowell.module.help

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.mvvm.bar.TitleBar
import com.example.mvvm.base.ContainerActivity
import com.example.mvvm.base.action.TitleBarAction
import com.example.mvvm.base.data.DataBindingConfig
import com.gyf.immersionbar.ImmersionBar
import com.miloyu.modelnet.response.HelpInfoVO
import com.miloyu.modelnet.response.SysNotice
import com.sx.micowell.BR
import com.sx.micowell.R
import com.sx.micowell.databinding.FragHelpCenterListBinding
import com.sx.micowell.framework.app.IntentKey
import com.sx.micowell.framework.app.MyFragment
import com.sx.micowell.framework.arouth.RouteManager
import com.sx.micowell.framework.arouth.RoutePath
import com.sx.micowell.framework.model.HelpModel
import com.sx.micowell.framework.model.MineNewsModel
import com.sx.micowell.module.message.NoticeListAdapter

/**
 * @author: YY
 * @time: 2021/8/9
 * @describe 帮助中心
 */
@Route(path = RoutePath.HELP_CENTER_LIST)
class HelpCenterListFragment : MyFragment<FragHelpCenterListBinding, ContainerActivity>(),TitleBarAction {

    lateinit var viewModel: HelpModel

    private var helpListAdapter = HelpListAdapter()

    override fun initViewModel() {
        viewModel = getFragmentScopeViewModel(HelpModel::class.java)
    }

    override fun getDataBindingConfig(): DataBindingConfig {
        return DataBindingConfig(R.layout.frag_help_center_list, BR.viewModel, viewModel)
    }

    override fun initView() {
        // 设置状态栏字体颜色
        ImmersionBar.with(this).statusBarDarkFont(true)
            .fitsSystemWindows(true).init()
        binding.title.setOnTitleBarListener(this)
    }




    override fun initData() {
        viewModel.getHelpInfo()
    }

    override fun initViewObservable() {
        super.initViewObservable()
        setHelpList()
    }

    private fun setHelpList() {
        //取消recyclerview单独的滑动效果
        binding.recyclerNotice.isNestedScrollingEnabled = false
        //设置布局管理器
        binding.recyclerNotice.layoutManager = LinearLayoutManager(context)

        viewModel.helpListData.observe(this) { data ->
            helpListAdapter = HelpListAdapter()
            helpListAdapter.data = data
            binding.recyclerNotice.adapter = helpListAdapter

            helpListAdapter.setOnItemClickListener { adapter, view, position ->
                val helpInfoBean: HelpInfoVO = adapter.getItem(position) as HelpInfoVO
                var bundle = Bundle()
                bundle.putSerializable(IntentKey.DATA, helpInfoBean)
                startContainerActivity(
                    (RouteManager.getInstance().getHelpDetailsFragment(helpInfoBean).javaClass.canonicalName), bundle)
            }
        }
    }

    override fun getTitleBar(): TitleBar {
        return binding.title
    }

    override fun onLeftClick(v: View?) {
        myActivity.finish()
    }

}